I'm running Electron ^18.0.1. I'm trying to get the events to "serial-port-added" / "serial-port-removed". From what I understand from the documentation the events should fire off when devices are connected/disconnect while the "select-serial-port" event has been fired but before the device selection callback has been returned.
My question: I haven't been able to figure out how to get the events to fire off. I'm not sure If have missunderstood the documentation/doing somthing wrong or if it's a bug?
mainWindow.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
event.preventDefault()
if (portList && portList.length > 0) {
// Tried many, many things before running the callback.
callback(portList[0].portId)
} else {
callback('') //Could not find any matching devices
}
})
mainWindow.webContents.session.on('serial-port-added', (event, port) => { // <-- Event not firing?
console.log('serial-port-added FIRED WITH', port)
})
mainWindow.webContents.session.on('serial-port-removed', (event, port) => { // <-- Event not firing?
console.log('serial-port-removed FIRED WITH', port)